package com.yy.config;

import com.yy.constant.UserConstant;
import com.yy.model.entity.User;
import com.yy.model.vo.LoginUserVO;
import com.yy.utils.ThreadLocalUtil;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


public class DefaultConfig {
    @Bean
    public Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }

    @Bean
    public RequestInterceptor requestInterceptor() {

        return template -> {
            LoginUserVO loginUserVO = (LoginUserVO) ThreadLocalUtil.getAttribute();
            if(loginUserVO!=null){
                String sessionId = loginUserVO.getSessionId();
                if (StringUtils.isNotBlank(sessionId)) {
                    template.header(UserConstant.USER_Seession_ID, sessionId);
                }
            }
        };

    }
}
